package kz.kstu.shop.business.entity.guide;

import kz.kstu.shop.business.entity.CommonEntityConstant;
import kz.kstu.shop.business.entity.Identifiable;
import kz.kstu.shop.business.entity.Synchronizable;

import javax.persistence.*;
import java.util.Date;

/**
 * @author Filipp_Stankevich
 *         created: 7/26/11 3:33 PM
 */
@NamedQuery(name = CommonEntityConstant.FIND_ALL_PRODUCTS, query = "select p from Product p")


@Entity
@Table(name = "PRODUCT")
public class Product implements Identifiable, Synchronizable {

    private Long id;
    private String barCode;
    private String name;
    private Long changeDate = 0L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "BAR_CODE")
    public String getBarCode() {
        return barCode;
    }

    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

    @Column(name = "NAME")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    @Column(name = "CHANGE_DATE")
    public Long getChangeDate() {
        return changeDate;
    }

    public void setChangeDate(Long changeDate) {
        this.changeDate = changeDate;
    }

    @Override
    public void beforePersist() {
        setChangeDate(new Date().getTime());
    }
}
